package com.miya.demo.handler.order;

import lombok.extern.slf4j.Slf4j;

/**
 * 订单处理责任链上下文
 *
 * @author CaiXiaowei
 * @date 2022/09/30
 */
@Slf4j
public class OrderHandlerChainContext<T> {

    OrderHandlerChainContext<T> next;  // 下个处理

    OrderHandlerChainContext<T> prev; // 上一个处理

    AbstractOrderHandler<T> handler;


    public OrderHandlerChainContext(AbstractOrderHandler handler) {
        this.handler = handler;
    }

    public void handler(T t) {
        this.handler.doWork(this, t);
    }

    private void preHandler(T t) {
        this.handler.cancelWork(this, t);
    }


    public void firePrevContext(T t) {
        if (this.prev != null) {
            this.prev.preHandler(t);
        }
    }

    public void fireNextContext(T t) {
        if (this.next != null) {
            this.next.handler(t);
        }
    }

}
